package com.ruoyi.business.base.controller;

import com.ruoyi.business.base.domain.SupplierData;
import com.ruoyi.business.base.domain.form.SupplierDataForm;
import com.ruoyi.business.base.domain.vo.SupplierDataSelect;
import com.ruoyi.business.base.service.ISupplierDataService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 供应商管理Controller
 *
 * @author lcy
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/base/supplierData")
@Api(tags = "供应商管理相关接口")
public class SupplierDataController extends BaseController {

    @Autowired
    private ISupplierDataService supplierDataService;

    /**
     * 查询供应商管理列表
     */
    @RequiresPermissions("base:supplierData:list")
    @GetMapping("/list")
    @Log(value = "查询供应商管理列表")
    @ApiOperation("查询供应商管理列表")
    public TableDataInfo list(SupplierDataForm form) {
        startPage();
        List<SupplierData> list = supplierDataService.selectSupplierDataList(form);
        return getDataTable(list);
    }


    /**
     * 查询供应商前端选择列表
     */
    @RequiresPermissions("base:supplierData:list")
    @GetMapping("/selectList")
    @Log(value = "查询供应商前端选择列表")
    @ApiOperation("查询供应商前端选择列表")
    public AjaxResult selectList() {
        List<SupplierDataSelect> list = supplierDataService.selectList();
        return success(list);
    }

    /**
     * 导出供应商管理列表
     */
    @RequiresPermissions("base:supplierData:export")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT,value = "导出供应商管理列表")
    @PostMapping("/export")
    @ApiOperation("导出供应商管理列表")
    public void export(HttpServletResponse response, SupplierDataForm form) {
        List<SupplierData> list = supplierDataService.selectSupplierDataList(form);
        ExcelUtil<SupplierData> util = new ExcelUtil<SupplierData>(SupplierData.class);
        util.exportExcel(response, list, "供应商管理数据");
    }

    /**
     * 获取供应商管理详细信息
     */
    @RequiresPermissions("base:supplierData:query")
    @GetMapping(value = "/{id}")
    @Log(value = "获取供应商管理详细信息")
    @ApiOperation("获取供应商管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(supplierDataService.selectSupplierDataById(id));
    }

    /**
     * 新增供应商管理
     */
    @RequiresPermissions("base:supplierData:add")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT,value = "新增供应商管理")
    @PostMapping("/insert")
    @ApiOperation("新增供应商管理")
    public AjaxResult add(@RequestBody SupplierData supplierData) {
        return toAjax(supplierDataService.insertSupplierData(supplierData));
    }

    /**
     * 修改供应商管理
     */
    @RequiresPermissions("base:supplierData:edit")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE,value = "修改供应商管理")
    @PutMapping("/update")
    @ApiOperation("修改供应商管理")
    public AjaxResult edit(@RequestBody SupplierData supplierData) {
        return toAjax(supplierDataService.updateSupplierData(supplierData));
    }

    /**
     * 删除供应商管理
     */
    @RequiresPermissions("base:supplierData:remove")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE,value = "删除供应商管理")
	@DeleteMapping("/delete/{ids}")
    @ApiOperation("删除供应商管理")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(supplierDataService.deleteSupplierDataByIds(ids));
    }
}
